<template>
  <div class="develop-wrapper">
    <div class="developAll">
      <!-- pc端 -->
      <div class="developPc">
        <div class="title">通过 OpenHarmony 兼容性认证的设备</div>
        <div class="develop">
          <div class="left-btn"
               :class="{ 'left-inset-btn': isInsetBtn }"
               @click="prevBtn">
            <img src="../../assets/images/left-btn.png" />
          </div>
          <div class="content"
               ref="mainAll">
            <div class="content-item"
                 v-for="routerItem in routerList"
                 :key="routerItem.id">
              <div class="img">
                <img :src="routerItem.logoImage"
                     width="220"
                     height="200" />
              </div>
              <div class="title">{{ routerItem.source }}|{{ routerItem.name }}</div>
              <div class="descript"><span>版本: </span>{{ routerItem.osVersion }}</div>
            </div>
          </div>
          <div class="right-btn"
               :class="{ 'right-inset-btn': isInsetBtn }"
               @click="nextBtn">
            <img src="../../assets/images/right-btn.png" />
          </div>
        </div>
        <div class="wrap-more">
          <div class="more"
               @click="goDevDetail">
            <div class="more-text">查看更多</div>
            <div class="more-btn"></div>
          </div>
        </div>
      </div>
      <!-- 移动端 -->
      <div class="mobleDev">
        <div class="middle">
          <div class="title">通过 OpenHarmony 兼容性认证的设备</div>
          <div class="content"
               id="slider">
            <div class="content-item"
                 v-for="routerItem in routerList"
                 :key="routerItem.id">
              <div class="img">
                <img :src="routerItem.logoImage"
                     width="200"
                     height="200" />
              </div>
              <div class="title">{{ routerItem.source }}|{{ routerItem.name }}</div>
              <div class="descript"><span>版本: </span>{{ routerItem.osVersion }}</div>
            </div>
          </div>
          <div class="wrap-more">
            <div class="more"
                 @click="goDevDetail">
              <div class="more-text">查看更多</div>
              <div class="more-btn"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  data () {
    return {
      isInsetBtn: false,
      screenWidth: document.body.clientWidth,
      // routerList: [
      //   {
      //     id: "1",
      //     name: "小熊派BearPi",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      //   {
      //     id: "2",
      //     name: "小熊派BearPi2222",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      //   {
      //     id: "3",
      //     name: "小熊派BearPi3333",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      //   {
      //     id: "4",
      //     name: "小熊派BearPi4444",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      //   {
      //     id: "5",
      //     name: "小熊派BearPi5555",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      //   {
      //     id: "6",
      //     name: "小熊派BearPi6666",
      //     description: "定位有什么,要什么,放弃什么",
      //     logoImage: "https//www.baidu.com",
      //     url: "https//www.baidu.com",
      //     source: "张三",
      //     attestStatus: "1",
      //     price: "150.54",
      //     sort: "1",
      //   },
      // ],
      elMainAll: "",
      scrollIdx: 0, // 滚动的次数
    };
  },
  computed: {
    ...mapState({
      routerList: (state) => state.devBoard.developmentList,
    }),
  },
  watch: {
    screenWidth: {
      handler (newVal) {
        if (newVal < 1200 && newVal > 1032) this.isInsetBtn = true;
        else if (newVal < 940 && newVal > 768) this.isInsetBtn = true;
        else this.isInsetBtn = false;
      },
      immediate: true,
      deep: true,
    },
  },
  created () {
    if (this.screenWidth < 1200 && this.screenWidth > 1032) {
      this.isInsetBtn = true;
    } else if (this.screenWidth < 940 && this.screenWidth > 768) {
      this.isInsetBtn = true;
    } else {
      this.isInsetBtn = false;
    }
    //开发板请求
    this.getDevelopment();
  },
  mounted () {
    this.elMainAll = this.$refs["mainAll"];
    window.addEventListener("resize", () => this.developScreenWidth(), false);
  },
  beforeDestroy () {
    window.removeEventListener(
      "resize",
      () => this.developScreenWidth(),
      false
    );
  },
  methods: {
    ...mapActions([
      "getInformation",
      "getDevelopment",
      "getQueryBanner",
      "getQueryBatch",
    ]),
    developScreenWidth () {
      window.screenWidth = document.body.clientWidth;
      this.screenWidth = window.screenWidth;
    },
    goDetail (item) {
      let u = navigator.userAgent;
      let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1;
      let isIos = !!u.match(/\(i[^;]+;(U;)? CPU.+Mac OS X/);
      console.log(item);
      if (item.url) {
        if (isIos) {
          window.location.href = item.url;
        } else {
          window.open(item.url);
        }
      }
    },
    // 开发板左按钮
    prevBtn: function () {
      let width = this.elMainAll.clientWidth;
      if (this.scrollIdx > 0) {
        this.scrollIdx--;
        console.log("scrollIdx", this.scrollIdx);
        this.elMainAll.scrollLeft = this.scrollIdx * Math.round(width / 4);
      } else {
        console.warn("已没有更多了");
      }
    },
    // 开发板右按钮
    nextBtn: function () {
      let width = this.elMainAll.clientWidth;
      if (this.scrollIdx < this.routerList.length - 4) {
        this.scrollIdx++;
        console.log("scrollIdx", this.scrollIdx);
        this.elMainAll.scrollLeft = this.scrollIdx * Math.round(width / 4);
      } else {
        console.warn("已没有更多了");
      }
    },
    // 开发板滑动
    scrollFn: function () {
      let width = this.elMainAll.clientWidth;
      this.elMainAll.scrollLeft = this.scrollIdx * Math.round(width / 4);
    },
    // 开发板更多
    goDevDetail () {
      this.$router.push({ name: "armList", query: { id: 6 } });
    },
  },
};
</script>

<style scoped lang="less">
@media screen and (min-width: 1032px) {
  .base {
    width: 1032px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .develop-wrapper {
    background: #fafafa;
    padding-top: 88px;
    .developAll {
      .base;
      flex-direction: column;
      .mobleDev {
        display: none;
      }
      .developPc {
        .title {
          height: 56px;
          line-height: 56px;
          font-size: 40px;
          font-family: HarmonyOS_Sans_SC_Medium;
          color: rgba(0, 0, 0, 0.85);
        }
        .develop {
          width: 100%;
          margin: 45px auto 40px;
          display: flex;
          position: relative;
          .left-btn {
            width: 72px;
            height: 72px;
            line-height: 72px;
            cursor: pointer;
            position: absolute;
            left: -84px;
            top: 149px;
          }
          .left-inset-btn {
            left: 0;
          }
          .right-btn {
            width: 72px;
            height: 72px;
            line-height: 72px;
            cursor: pointer;
            position: absolute;
            right: -84px;
            top: 149px;
          }
          .right-inset-btn {
            right: 0;
          }
          .content {
            width: 100%;
            display: flex;
            flex-direction: row;
            white-space: nowrap;
            overflow: hidden;
            .content-item {
              min-width: calc(92% / 4);
              padding: 40px 20px 24px;
              box-sizing: border-box;
              background: #fff;
              border-radius: 8px;
              margin-right: 21px;
              border: 1px solid #fff;
              .img {
                width: 100%;
                margin-bottom: 24px;
                img {
                  width: 100%;
                }
              }
              .title {
                width: 100%;
                height: 44px;
                line-height: 22px;
                font-size: 16px;
                font-family: HarmonyOS_Sans_SC_Medium;
                color: rgba(0, 0, 0, 0.85);
                white-space: normal;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                word-break: normal;
                word-wrap: break-word;
                -webkit-box-orient: vertical;
                -webkit-box-pack: center;
                -webkit-box-align: center;
                -webkit-line-clamp: 2;
              }
              .descript {
                height: 44px;
                line-height: 22px;
                font-size: 14px;
                font-family: HarmonyOS_Sans_SC;
                color: rgba(0, 0, 0, 0.55);
                margin-top: 16px;
                word-break: normal;
                word-wrap: break-word;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                white-space: normal;
                -webkit-box-orient: vertical;
                -webkit-box-pack: center;
                -webkit-box-align: center;
                -webkit-line-clamp: 2;
              }
            }
            // .content-item:hover {
            //   box-shadow: 0px 12px 24px 0px rgba(0, 166, 249, 0.12);
            //   border: 1px solid #00a6f9;
            // }
          }
        }
        .wrap-more {
          display: flex;
          justify-content: flex-end;
          padding-bottom: 56px;
          .more {
            width: 140px;
            height: 48px;
            font-size: 16px;
            font-family: HarmonyOS_Sans_SC;
            color: rgba(0, 0, 0, 0.85);
            line-height: 48px;
            border: 1px solid rgba(0, 0, 0, 0.15);
            border-radius: 24px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            .more-btn {
              margin-left: 4px;
              width: 24px;
              height: 24px;
              background: url("../../assets/images/right.png") no-repeat 100%
                100%;
            }
            &:hover {
              background: #00a6f9;
              border: 1px solid #00a6f9;
              color: #fff;
              .more-btn {
                background: url("../../assets/images/right-w.png") no-repeat
                  100% 100%;
              }
            }
          }
        }
      }
    }
  }
}
@media screen and (min-width: 768px) and (max-width: 1032px) {
  .base {
    width: 768px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .develop-wrapper {
    background: #fafafa;
    padding-top: 72px;
    .developAll {
      .base;
      flex-direction: column;
      .mobleDev {
        display: none;
      }
      .developPc {
        .title {
          height: 56px;
          line-height: 56px;
          font-size: 40px;
          font-family: HarmonyOS_Sans_SC_Medium;
          color: rgba(0, 0, 0, 0.85);
        }
        .develop {
          width: 100%;
          margin: 0 auto;
          display: flex;
          margin-bottom: 40px;
          margin-top: 45px;
          position: relative;
          .left-btn {
            width: 72px;
            height: 72px;
            line-height: 72px;
            cursor: pointer;
            position: absolute;
            left: -84px;
            top: 149px;
          }
          .left-inset-btn {
            left: 0;
          }
          .right-btn {
            width: 72px;
            height: 72px;
            line-height: 72px;
            cursor: pointer;
            position: absolute;
            right: -84px;
            top: 149px;
          }
          .right-inset-btn {
            right: 0;
          }
          .content {
            width: 100%;
            display: flex;
            flex-direction: row;
            white-space: nowrap;
            overflow: hidden;
            .content-item {
              min-width: calc(92% / 3);
              padding: 40px 20px 24px;
              box-sizing: border-box;
              background: #fff;
              border-radius: 8px;
              margin-right: 21.5px;
              border: 1px solid #fff;
              .img {
                width: 100%;
                margin-bottom: 24px;
                img {
                  width: 100%;
                }
              }
              .title {
                height: 44px;
                line-height: 22px;
                font-size: 16px;
                font-family: HarmonyOS_Sans_SC_Medium;
                color: rgba(0, 0, 0, 0.85);
                word-break: normal;
                word-wrap: break-word;
                overflow: hidden;
                white-space: normal;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-box-pack: center;
                -webkit-box-align: center;
                -webkit-line-clamp: 2;
              }
              .descript {
                margin-top: 16px;
                height: 44px;
                line-height: 22px;
                font-size: 14px;
                font-family: HarmonyOS_Sans_SC;
                color: rgba(0, 0, 0, 0.55);
                white-space: normal;
                word-break: normal;
                word-wrap: break-word;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-box-pack: center;
                -webkit-box-align: center;
                -webkit-line-clamp: 2;
              }
            }
            // .content-item:hover {
            //   box-shadow: 0px 12px 24px 0px rgba(0, 166, 249, 0.12);
            //   border: 1px solid #00a6f9;
            // }
          }
        }
        .wrap-more {
          display: flex;
          justify-content: flex-end;
          padding-bottom: 56px;
          .more {
            width: 140px;
            height: 48px;
            line-height: 48px;
            font-size: 16px;
            font-family: HarmonyOS_Sans_SC;
            color: rgba(0, 0, 0, 0.85);
            border: 1px solid rgba(0, 0, 0, 0.15);
            border-radius: 24px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            .more-btn {
              margin-left: 4px;
              width: 24px;
              height: 24px;
              background: url("../../assets/images/right.png") no-repeat 100%
                100%;
            }
            &:hover {
              background: #00a6f9;
              border: 1px solid #00a6f9;
              color: #fff;
              .more-btn {
                background: url("../../assets/images/right-w.png") no-repeat
                  100% 100%;
              }
            }
          }
        }
      }
    }
  }
}
@media screen and (max-width: 768px) {
  .base {
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .developAll {
    background: #fafafa;
    .developPc {
      display: none;
    }
    .mobleDev {
      .base;
      display: block;
      padding-bottom: 24px;
      justify-content: unset;
      background: #fafafa;
      .middle {
        width: 100%;
        display: flex;
        flex-direction: column;
        .title {
          height: 28px;
          line-height: 28px;
          font-size: 20px;
          font-family: HarmonyOS_Sans_SC_Medium;
          color: rgba(0, 0, 0, 0.85);
          padding: 24px 0 24px 12px;
        }
        .content {
          width: 100%;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          flex-wrap: nowrap;
          overflow-x: scroll;
          white-space: nowrap;
          .content-item {
            min-width: 240px;
            height: 350px;
            background: #ffffff;
            box-shadow: 0px 12px 24px 0px rgba(0, 0, 0, 0.02);
            border-radius: 8px;
            margin-right: 12px;
            .img {
              margin: 20px 20px 24px 20px;
            }
            .title {
              padding: 0 0 16px 20px;
              height: 44px;
              line-height: 22px;
              font-size: 16px;
              font-family: HarmonyOS_Sans_SC_Medium;
              color: rgba(0, 0, 0, 0.85);
              display: -webkit-box;
              text-overflow: ellipsis;
              white-space: normal;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            .descript {
              padding-left: 20px;
              height: 44px;
              line-height: 22px;
              font-size: 14px;
              font-family: HarmonyOS_Sans_SC;
              color: rgba(0, 0, 0, 0.55);
              display: -webkit-box;
              text-overflow: ellipsis;
              white-space: normal;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
          }
          .content-item:nth-child(1) {
            margin-left: 16px;
          }
        }
        // .content::-webkit-scrollbar {
        //   display: none;
        // }
        .wrap-more {
          display: flex;
          justify-content: flex-end;
          padding: 0 12px;
          .more {
            width: 140px;
            height: 48px;
            line-height: 48px;
            font-size: 16px;
            font-family: HarmonyOS_Sans_SC;
            color: rgba(0, 0, 0, 0.85);
            margin-top: 24px;
            border: 1px solid rgba(0, 0, 0, 0.15);
            border-radius: 24px;
            display: flex;
            justify-content: center;
            align-items: center;
            .more-btn {
              margin-left: 4px;
              width: 24px;
              height: 24px;
              background: url("../../assets/images/right.png") no-repeat 100%
                100%;
            }
            &:hover {
              background: #00a6f9;
              color: #fff;
              .more-btn {
                background: url("../../assets/images/right-w.png") no-repeat
                  100% 100%;
              }
            }
          }
        }
      }
    }
  }
}
</style>
